package com.djl.zenithbite.repository.impl;

import com.djl.zenithbite.entity.Store;
import com.djl.zenithbite.entity.StoreExample;
import com.djl.zenithbite.entity.User;
import com.djl.zenithbite.entity.UserExample;
import com.djl.zenithbite.repository.StoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Repository
public class StoreRepositoryImpl {

    @Autowired
    private StoreMapper storeMapper;

    public Store queryById(int storeId){
        Store store = storeMapper.selectByPrimaryKey(storeId);
        return store;
    }


    /**
     * 通storeName查询
     * @param storeName
     * @return
     */
    public Store selectByStoreName(String storeName){
        StoreExample example = new StoreExample();
        StoreExample.Criteria criteria = example.createCriteria();
        criteria.andStoreNameEqualTo(storeName);
        List<Store> stores = storeMapper.selectByExampleWithBLOBs(example);
        return Optional.ofNullable(stores).orElse(new ArrayList<>()).stream().findFirst().orElse(null);
    }

}
